<%@page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8"%>
<%@include file="/includes/taglibs.jsp"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
            
    <script type="text/javascript">
    <!-- 
    $(document).ready(function() {
    	$('#doSaveBtn').click(function() {
    		var menuTypeId = $('#menuTypeId').val();//程式類別
    		var menuItemPk = $('#menuItemPk').val();//上層程式
    		var menuNoCreate = $('#menuNoCreate').val();//程式代號
    		var actionNameCreate = $('#actionNameCreate').val();//程式名稱
    		var orderNoCreate = $("#orderNoCreate").val();//排序
    		var actionPageCreate = $('#actionPageCreate').val();//程式Page
    		var actionBeanClassCreate = $('#actionBeanClassCreate').val();//程式類別名稱
    		var errorMessage = '';
    		if (menuTypeId == '0'){//程式類別為-程式群組
    			$('#menuItemPk').attr("disabled",true);
    		} else if(menuTypeId == '1'){//程式類別為-程式功能
    			$('#menuItemPk').attr("disabled",false);
    			if(menuItemPk == ''){
    				errorMessage = '程式類別為程式功能,上層程式不可空白!!';
    			}
    		}
    		
    		if (menuNoCreate == '')
    		{
    		    if (errorMessage != '') errorMessage = errorMessage + '<br>';
    		    errorMessage = errorMessage + '程式代號不可空白!!';
    		}else{
				 var count = menuNoCreate.length;
				 var strLength = 0;					 
				 for(var i = 0; i < count; i++){
					  if(menuNoCreate.charCodeAt(i) < 0 || menuNoCreate.charCodeAt(i) > 255){
					   	strLength += 3;//漢字編碼在0-255之外，oracle數據庫是UTF-8編碼，一個漢字，對應數據庫varchar2的3個byte。
					  }else{
					  	 strLength += 1;
					  }
				 }
				 if(strLength > 50){
				 	 if (errorMessage != '') errorMessage = errorMessage + '<br>';
    		    	 errorMessage = errorMessage + '程式代號不可超過50碼!!';
				 }
    		}
    		    		
            if (actionNameCreate == '')
    		{
    		    if (errorMessage != '') errorMessage = errorMessage + '<br>';
    		    errorMessage = errorMessage + '程式名稱不可空白!!';
    		}else{
				 var count = actionNameCreate.length;
				 var strLength = 0;					 
				 for(var i = 0; i < count; i++){
					  if(actionNameCreate.charCodeAt(i) < 0 || actionNameCreate.charCodeAt(i) > 255){
					   	strLength += 3;//漢字編碼在0-255之外，oracle數據庫是UTF-8編碼，一個漢字，對應數據庫varchar2的3個byte。
					  }else{
					  	 strLength += 1;
					  }
				 }
				 if(strLength > 255){
				 	 if (errorMessage != '') errorMessage = errorMessage + '<br>';
    		    	 errorMessage = errorMessage + '程式名稱不可超過255碼!!';
				 }
    		} 
    		
    		if(actionPageCreate != '')
    		{
				 var count = actionPageUpdate.length;
				 var strLength = 0;					 
				 for(var i = 0; i < count; i++){
					  if(actionPageCreate.charCodeAt(i) < 0 || actionPageCreate.charCodeAt(i) > 255){
					   	strLength += 3;//漢字編碼在0-255之外，oracle數據庫是UTF-8編碼，一個漢字，對應數據庫varchar2的3個byte。
					  }else{
					  	 strLength += 1;
					  }
				 }
				 if(strLength > 255){
				 	 if (errorMessage != '') errorMessage = errorMessage + '<br>';
    		    	 errorMessage = errorMessage + '程式PAGE不可超過255碼!!';
				 }
    		}
    		
    		if(actionBeanClassCreate != '')
    		{
				 var count = actionBeanClassCreate.length;
				 var strLength = 0;					 
				 for(var i = 0; i < count; i++){
					  if(actionBeanClassCreate.charCodeAt(i) < 0 || actionBeanClassCreate.charCodeAt(i) > 255){
					   	strLength += 3;//漢字編碼在0-255之外，oracle數據庫是UTF-8編碼，一個漢字，對應數據庫varchar2的3個byte。
					  }else{
					  	 strLength += 1;
					  }
				 }
				 if(strLength > 255){
				 	 if (errorMessage != '') errorMessage = errorMessage + '<br>';
    		    	 errorMessage = errorMessage + '程式類別名稱不可超過255碼!!';
				 }
    		}
    		
            if(orderNoCreate != '')
    		{
				if(isNaN(orderNoCreate)) {
					if (errorMessage != '') errorMessage = errorMessage + '<br>';
    		    	errorMessage = errorMessage + '排序必須輸入數字!!';
				} 
    		}
            if (errorMessage != '')
            {
                showErrorMessageDialog(errorMessage);
                return false;
            }
           
    		return true;
				
		});
		//下拉框聯動，改變上層程式可編輯狀態
		$('#menuTypeId').change(function(){  
    		var menuTypeId = $('#menuTypeId').val();//程式類別
    		if(menuTypeId == '0'){
    			$('#menuItemPk').attr("disabled",true);
    		}else if(menuTypeId == '1'){
    			$('#menuItemPk').attr("disabled",false);
    		}  	
    	}); 
    	
    	$("#doCancelBtn").click(function() {
			$("#hidden\\.doCancelBtn").trigger('click');
		});
		
    	<c:if test="${not empty actionBean.message}">
   			showMessageDialog('<c:out value="${actionBean.message }" escapeXml="false"/>');
		</c:if>	
    });
    
    //-->
    </script>
</head>
<body>

	<div id="smallQueryForm"></div>
<stripes:form id="queryMenuItemForm" beanclass="com.feib.stms.action.Stms9004ActionBean" method="post">            
	<div id="queryForm">
		<table>
			<tr>
				<td colspan="5" class="queryHeader">新增</td>
			</tr>
			<tr>
				<th>程式類別</th>
				<td colspan="4">
                     <stripes:select id="menuTypeId" name="menuTypeId">
	                      <stripes:option value="0" label="程式群組"/>
	                      <stripes:option value="1" label="程式功能"/>
                     </stripes:select>
                </td>
			</tr>
			<tr>
				<th>上層程式</th>
				<td colspan="4">
                     <stripes:select id="menuItemPk" name="createMenuItem.parentMenuItem.menuItemPk"  disabled="true">
                     	<stripes:option value="" label="-- 請選擇 --"/>
                     	<c:forEach items="${actionBean.menuItems }" var="menuItem" varStatus="rowstat">
	                      <stripes:option value="${menuItem.menuItemPk }" label="${menuItem.actionName }"/>
	                    </c:forEach>  
                     </stripes:select>
                </td>
			</tr>
			<tr>
				<th>程式代號<span id="mustKeyInStar">**</span></th>
				<td colspan="4"><stripes:text id="menuNoCreate" maxlength="50" name="createMenuItem.menuNo" size="25" /></td>
			</tr>
			<tr>
				<th>程式名稱<span id="mustKeyInStar">**</span></th>
				<td colspan="4"><stripes:text id="actionNameCreate" maxlength="255" name="createMenuItem.actionName" size="25" /></td>
			</tr>
			<tr>
				<th>程式PAGE</th>
				<td colspan="4"><stripes:text id="actionPageCreate" maxlength="255" name="createMenuItem.actionPage" size="25" /></td>
			</tr>
			<tr>
				<th>程式類別名稱</th>
				<td colspan="4"><stripes:text id="actionBeanClassCreate" maxlength="50" name="createMenuItem.actionBeanClass" size="25" /></td>
			</tr>
			<tr>
				<th>排序</th>
				<td colspan="4"><stripes:text id="orderNoCreate" maxlength="50" name="createMenuItem.orderNo" size="25" /></td>
			</tr>
			<tr>
				<th>是否有效</th>
				<td colspan="4">
					<stripes:select id="enabledCreate" name="createMenuItem.enabled">      
	                      <stripes:option value="1" label="啟用"/>
	                      <stripes:option value="0" label="停用"/>
                    </stripes:select>
				</td>
			</tr>
			<tr>
				<th>券商可用</th>
				<td colspan="4">
					<stripes:select id="securitiesCreate" name="createMenuItem.securities">      
	                      <stripes:option value="true" label="啟用"/>
	                      <stripes:option value="false" label="停用"/>
                    </stripes:select>
				</td>
			</tr>			
			<tr>
				<td colspan="5" class="queryFunction">
					<stripes:hidden id="operation" name="operation" />
					<stripes:submit id="doSaveBtn" name="doSave" value="確認" class="formBtn"/>
					<stripes:submit id="doCancelBtn" name="doCancel" value="取消" class="formBtn"/>
				</td>
			</tr>
		</table>
	</div>
			<!--查詢條件-->
			<stripes:hidden id="hidden.qryMenuTypeIdForm" name="qryMenuTypeIdForm" />
			<stripes:hidden id="hidden.qryMenuIdForm" name="qryMenuIdForm" />
			<stripes:hidden id="hidden.qryActionNameForm" name="qryActionNameForm" />
			<stripes:hidden id="hidden.queryResult.pageNumber" name="queryResult.pageNumber" />
			<stripes:hidden id="hidden.queryResult.sortCriterion" name="queryResult.sortCriterion" />
			<stripes:hidden id="hidden.queryResult.sortDirection" name="queryResult.sortDirection" />		
			<!--新增表單參數-->
			<stripes:hidden id="hidden.createMenuItem.parentMenuItem.menuItemPk" name="createMenuItem.parentMenuItem.menuItemPk" />
			<stripes:hidden id="hidden.createMenuItem.menuNo" name="createMenuItem.menuNo" />
			<stripes:hidden id="hidden.createMenuItem.actionName" name="createMenuItem.actionName" />
			<stripes:hidden id="hidden.createMenuItem.actionPage" name="createMenuItem.actionPage" />
			<stripes:hidden id="hidden.createMenuItem.actionBeanClass" name="createMenuItem.actionBeanClass" />
			<stripes:hidden id="hidden.createMenuItem.orderNo" name="createMenuItem.orderNo" />
			<stripes:hidden id="hidden.createMenuItem.enabled" name="createMenuItem.enabled" />
			<stripes:hidden id="hidden.createMenuItem.securities" name="createMenuItem.securities" />			
</stripes:form>

<!-- 取消使用 -->	
<div style="display: none;">
<stripes:form id="hidden.queryMenuItemForm" beanclass="com.feib.stms.action.Stms9004ActionBean" method="post" onsubmit="javascript: waitingDialog({});">
	<!-- 查詢條件 -->
	<stripes:hidden id="hidden.qryMenuTypeIdForm" name="qryMenuTypeIdForm" />
	<stripes:hidden id="hidden.qryMenuIdForm" name="qryMenuIdForm" />
	<stripes:hidden id="hidden.qryActionNameForm" name="qryActionNameForm" />
	<stripes:hidden id="hidden.queryResult.pageNumber" name="queryResult.pageNumber" />
	<stripes:hidden id="hidden.queryResult.sortCriterion" name="queryResult.sortCriterion" />
	<stripes:hidden id="hidden.queryResult.sortDirection" name="queryResult.sortDirection" />
	<!-- 分頁信息 -->
	<stripes:hidden id="hidden.queryResult.pageNumber" name="queryResult.pageNumber" />
	<stripes:hidden id="hidden.queryResult.sortCriterion" name="queryResult.sortCriterion" />
	<stripes:hidden id="hidden.queryResult.sortDirection" name="queryResult.sortDirection" />
	<stripes:submit id="hidden.doCancelBtn" name="doCancel" value="取消" class="formBtn"/>
</stripes:form>
</div>
</body>
</html>
